package com.tian.service;

import com.tian.entity.RepaymentPlain;
import com.tian.service.LoanCalculatorPlainStrategy;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.text.DecimalFormat;
import java.util.List;

/**
 * @author tianwc  公众号：java后端技术全栈、面试专栏
 * @version 1.0.0
 * @date 2023年09月20日 15:29
 * 在线刷题 1200+题和1000+篇干货文章：<a href="https://woaijava.cc/">博客地址</a>
 * <p>
 * 等额本息
 */
@Slf4j
@Service
public class LoanCalculatorPlainPrincipalInterestStrategy implements LoanCalculatorPlainStrategy {
    @Override
    public List<RepaymentPlain> calculator(Integer numberOfPayments, BigDecimal loanAmount, BigDecimal annualInterestRate) {

        return null;
    }
   /* public static void main(String[] args) {
        double loanAmount = 100000; // 贷款金额
        double annualInterestRate = 4.8; // 年利率
        int numberOfPayments = 16; // 还款期数

        double monthlyInterestRate = annualInterestRate / 100 / 12; // 月利率

        double monthlyPayment = calculateMonthlyPayment(loanAmount, monthlyInterestRate, numberOfPayments);
        double totalPayment = monthlyPayment * numberOfPayments;

        DecimalFormat df = new DecimalFormat("#.##");

        System.out.println("每月还款金额：" + df.format(monthlyPayment));
        System.out.println("总还款金额：" + df.format(totalPayment));

        System.out.println("\n还款计划：");
        System.out.println("期数\t\t本金\t\t利息\t\t本息合计");

        for (int i = 1; i <= numberOfPayments; i++) {
            double interest = loanAmount * monthlyInterestRate;
            double principal = monthlyPayment - interest;
            loanAmount -= principal;

            System.out.println(i + "\t\t" + df.format(principal) + "\t\t" + df.format(interest) + "\t\t" + df.format(monthlyPayment));
        }
    }

    public static double calculateMonthlyPayment(double loanAmount, double monthlyInterestRate, int numberOfPayments) {
        return loanAmount * monthlyInterestRate * Math.pow(1 + monthlyInterestRate, numberOfPayments)
                / (Math.pow(1 + monthlyInterestRate, numberOfPayments) - 1);
    }*/
}
